<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('商户列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>主体：</label>
                            <select name="subjectType" th:with="type=${@dict.getType('sys_partner_type')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label style="width: 90px;">选择合作商：</label>
                            <input id="treeId" name="partnerId" style="display: none;"/>
                            <input type="text" onclick="selectPartnerTree()" id="treeName" placeholder="点击选择合作商"
                                   readonly="true">
                        </li>
                        <li class="select-time">
                            <label>签约时间：</label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="startTime"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="endTime"/>
                        </li>
                        <li>
                            <label style="width: 105px;">关键字查询字段：</label>
                            <select name="fields">
                                <option value="code" selected>商户编号</option>
                                <option value="fullName">姓名</option>
                                <option value="phone">联系方式</option>
                            </select>
                            <input type="text" name="keywords"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <!--<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:merchant:add">-->
            <!--<i class="fa fa-plus"></i> 添加-->
            <!--</a>-->
            <!--            <a class="btn btn-primary single disabled" onclick="$.operate.edit()"-->
            <!--               shiro:hasPermission="system:merchant:edit">-->
            <!--                <i class="fa fa-edit"></i> 修改-->
            <!--            </a>-->
            <!--            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"-->
            <!--               shiro:hasPermission="system:merchant:remove">-->
            <!--                <i class="fa fa-remove"></i> 删除-->
            <!--            </a>-->
            <!--<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:merchant:export">-->
                <!--<i class="fa fa-download"></i> 导出-->
            <!--</a>-->
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:merchant:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:merchant:remove')}]];
    var subjectTypeDatas = [[${@dict.getType('sys_partner_type')}]];
    var prefix = ctx + "system/merchant";

    var seeDetailFlag = [[${@permission.hasPermi('system:partner:seeDetail')}]];

    var putUpBaseFlag = [[${@permission.hasPermi('system:merchant:putUpBase')}]];

    var seeDetailFlag = [[${@permission.hasPermi('system:merchant:seeDetail')}]];


    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "商户",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '',
                    visible: false
                },
                {
                    field: 'id',
                    title: '商户编号'
                },
                {
                    field: 'fullName',
                    title: '商户姓名',
                    formatter: function (value, row, index) {
                        return value + "(" + $.table.selectDictLabel(subjectTypeDatas, row.subjectType) + ")";
                    }
                },
                {
                    field: 'phone',
                    title: '联系方式'
                },
                {
                    field: 'partnerFullName',
                    title: '直营合作商'
                },
                {
                    field: 'shareRatio',
                    title: '分成比例'
                },
                {
                    field: 'totalRevenue',
                    title: '商户总收益'
                },
                {
                    field: 'cashoutMoney',
                    title: '可提现金额'
                },
                {
                    field: 'frozenMoney',
                    title: '已冻结金额'
                },
                {
                    field: 'signingTime',
                    title: '签约时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];

                        // 查询直营合作商层级关系
                        actions.push('<a class="btn btn-default btn-xs ' + seeDetailFlag + '" href="javascript:void(0)" onclick="seeTier(\'' + row.partnerId + '\')"><i class="fa fa-navicon"></i>查看层级关系</a> ');

                        // 设置
                        actions.push('<a class="btn btn-info btn-xs ' + putUpBaseFlag + '" href="javascript:void(0)" onclick="putUpBase(\'' + row.id + '\')"><i class="fa fa-gear"></i>设置</a> ');

                        // 查看详情
                        actions.push('<a class="btn btn-primary btn-xs ' + seeDetailFlag + '" href="javascript:void(0)" onclick="seeDetail(\'' + row.id + '\')"><i class="fa fa-edit"></i>查看详情</a> ');


                        // actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        // actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function seeTier(id) {
        var prefix = ctx + "system/partner";
        var url = prefix + "/selectPartnerTree/" + id;
        var width = null;
        var height = null;
        if ($.common.isMobile()) {
            width = 'auto';
            height = 'auto';
        }
        if ($.common.isEmpty(url)) {
            url = "/404.html";
        }
        if ($.common.isEmpty(width)) {
            width = 500;
        }
        if ($.common.isEmpty(height)) {
            height = 660;
        }
        layer.open({
            type: 2,
            area: [width + 'px', height + 'px'],
            fix: false,
            maxmin: true,
            shade: 0.3,
            title: "合作商层级关系",
            content: url,
            btn: ['关闭'],
            // 弹层外区域关闭
            shadeClose: true,
            cancel: function (index) {
                return true;
            }
        });
    }

    function putUpBase(id) {
        var url = prefix + "/putUpBase/" + id;
        $.modal.open("设置", url, 800, 460);
    }

    // 查看详情
    function seeDetail(id) {
        // TODO
        var url = prefix + "/seeDetail/" + id;
        var width = null;
        var height = null;
        if ($.common.isMobile()) {
            width = 'auto';
            height = 'auto';
        }
        if ($.common.isEmpty(url)) {
            url = "/404.html";
        }
        if ($.common.isEmpty(width)) {
            width = 800;
        }
        if ($.common.isEmpty(height)) {
            height = 660;
        }
        layer.open({
            type: 2,
            area: [width + 'px', height + 'px'],
            fix: false,
            maxmin: true,
            shade: 0.3,
            title: "查看商户详情",
            content: url,
            btn: ['关闭'],
            // 弹层外区域关闭
            shadeClose: true,
            cancel: function (index) {
                return true;
            }
        });
    }

    /*合作商-新增-选择父部门树*/
    function selectPartnerTree() {
        var prefix = ctx + "system/partner";
        var options = {
            title: '合作商选择',
            width: "380",
            url: prefix + "/selectPartnerTree/" + $("#treeId").val(),
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {
        var body = layer.getChildFrame('body', index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        layer.close(index);
    }


</script>
</body>
</html>